package com.qf.cls.application.controller;

import com.qf.cls.application.entity.Cls;
import com.qf.cls.application.service.ClsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/cls")
public class ClsController {

    @Value("${server.port}")
    private int port;

    @Autowired
    private ClsService clsService;

    @RequestMapping("/get")
    public String get(String name){
        System.out.println("查询" + name + "所在的班级号！");
        return switch (name) {
            case "张三" -> "一年一班";
            case "李四" -> "一年二班";
            default -> {
                try {
                    Thread.sleep(60000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                yield "没有找到该学生的班级号";
            }
        } + port;
    }


    @RequestMapping("/insert")
    public String insert(){
        clsService.save(new Cls().setCname("一年一班"));
        return "success";
    }
}
